/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:com.cesgroup.zw.spring.boot.util.math</p>
 * <p>File:BigDecimalUtil.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 May 28, 2019 11:36:24 AM
 */
package com.cesgroup.zw.spring.boot.supports.util.math;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date May 28, 2019 11:36:24 AM
 * @version 1.0.2019
 */
public abstract class BigDecimalUtil {

	public static BigDecimal valueOf(int value) {
		return new BigDecimal(value).setScale(2, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal valueOf(double value) {
		return new BigDecimal(value).setScale(2, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal valueOf(int value, int scale) {
		return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal valueOf(double value, int scale) {
		return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP);
	}

	public static BigDecimal[] valueOf(double[] values) {
		BigDecimal[] decimals = new BigDecimal[values.length];
		for (int i = 0, size = values.length; i < size; i++) {
			decimals[i] = new BigDecimal(values[i]);
		}
		return decimals;
	}
	
	public static BigDecimal[] valueOf(double[] values, int scale) {
		BigDecimal[] decimals = new BigDecimal[values.length];
		for (int i = 0, size = values.length; i < size; i++) {
			decimals[i] = new BigDecimal(values[i]).setScale(scale, RoundingMode.HALF_UP);
		}
		return decimals;
	}
}
